<template>
  <div>

      <div class="title">表信息</div>
      <detail-list>
        <detail-list-item term="表分类">{{model.categoryName}}</detail-list-item>
        <detail-list-item term="表名">{{model.tableName}}</detail-list-item>
        <detail-list-item term="表编码">{{model.tableCode}}</detail-list-item>
        <detail-list-item term="表描述">{{model.tableDesc}}</detail-list-item>
        <detail-list-item term="表描述">
          <span v-if="model.tableType === 'FACT'">事实表</span>
          <span v-else-if="model.tableType === 'DIMENSION'">维度表</span>
        </detail-list-item>
        <detail-list-item term="表状态">
          <span v-if="model.status === 'DRAFT'">拟稿</span>
          <span v-else-if="model.status === 'PUBLISHED'">已发布</span>
          <span v-else-if="model.status === 'UNPUBLISHED'">未发布</span>
        </detail-list-item>
        <detail-list-item term="表数据源">{{model.tableSourceName}}</detail-list-item>
      </detail-list>

      <a-divider type="horizontal" />

      <div class="title">字段信息</div>
      <a-table bordered :data-source="dataSource" :columns="columns"  :pagination="false" :scroll="{ y: '400px' }" :fixed-header="true" >
        <template slot="isKey-column" slot-scope="text, record">
          <a-tag v-if="record.isKey === 0" color="yellow">否</a-tag>
          <a-tag v-else-if="record.isKey === 1" color="green">是</a-tag>
        </template>
      </a-table>

      <a-divider type="horizontal" />

      <div class="title">字段信息</div>
      <detail-list>
        <detail-list-item term="联合索引键">{{model.keyCodes}}</detail-list-item>
        <detail-list-item term="分区键">{{model.partitionKey}}</detail-list-item>
        <detail-list-item term="分桶键">{{model.disKey}}</detail-list-item>
        <detail-list-item term="分桶数">{{model.disNum}}</detail-list-item>
      </detail-list>

  </div>
</template>
<script>
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item
import {getInfoCollectSourceById} from  '@api/apiDs'
import STable from '@/components/table/'
import { getDAListByTableId,getExtInfoById } from '@api/apiDatalib'

export default  {
  components: { DetailList,DetailListItem,STable },
  data () {
    return {
      name: "源表详情",
      visible: false,
      model:{},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      columns: [
        {
          title: '字段编码',
          dataIndex: 'logicCode',
          key:'logicCode',
        },
        {
          title: '字段名称',
          dataIndex: 'logicName',
          key:'logicName',
        },
        {
          title: '是否是key',
          dataIndex: 'isKey',
          scopedSlots: { customRender: 'isKey-column' },
        },
        {
          title: '字段类型',
          dataIndex: 'logicDataType',
          key:'logicDataType',
        },
        {
          title: '长度',
          dataIndex: 'logicDataLength',
          key:'logicDataLength',
        },
        {
          title: '小数位数',
          dataIndex: 'logicDataDecimal',
          key:'logicDataDecimal',
        },
      ],
      dataSource:[],
    }
  },
  methods: {
    info(record){
      this.visible=true
      console.log("详情",record);
      this.model = record;
      if(record.tableSourceId != null){
        getInfoCollectSourceById({id:record.tableSourceId}).then((res) => {
          console.log("数据源",res)
          if (res.success) {
            this.model.tableSourceName = res.result.sourceName
          } else {
            this.$message.warning(res.message)
          }
        })
      }
      let param={"tableId":this.model.id}
      getDAListByTableId(param).then((res) => {
        if(res.success){
          this.dataSource = res.result;
          this.loading = false;
        }
      })

      getExtInfoById(param).then((res) => {
        if(res.success){
          this.model.keyCodes = res.result.keyCodes
          this.model.partitionKey = res.result.partitionKey
          this.model.disKey = res.result.disKey
          this.model.disNum = res.result.disNum
        }
      })


    }
  }
}
</script>

<style lang="less" scoped>
.title {
  color: rgba(0,0,0,.85);
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 16px;
}
</style>